﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Zgq.CommonTools
{
    public static class ExceptionHelper
    {
        public static Exception GetInnerException(this Exception ex)
        {
            while (ex.InnerException != null)
            {
                ex = ex.InnerException;
            }

            return ex;
        }

        public static void HandleException(Exception ex)
        {
            if (typeof(C5Exception) != ex.GetType())
                throw GetInnerException(ex);
            else
                throw ex;
        }

        public static Exception GetInnerException(this Exception ex, out bool isSystemException)
        {
            isSystemException = false;
            while (ex.InnerException != null)
            {
                if (typeof(C5Exception) != ex.GetType())
                    isSystemException = true;
                ex = ex.InnerException;
            }

            return ex;
        }
    }
}
